package TUI;

import java.util.Scanner;

/**
 * This is a user interface and the main menu for this application.
 * 
 * @author Group 4, dm82
 * @version 14-12-12
 */
public class MainMenuUI
{
    /**
     * Constructor for objects of class MainMenuUI
     */
    public MainMenuUI()
    {
    }
    
    /**
     * This menu starts the appliication by showing the main menu
     */
    public void start()
    {
        boolean exit = false;
        while(!exit)
        {
            int choise = writeMainMenu();
            switch(choise)
            {
                case 1:
                    print("case");
                    startAddressBook();
                    break;
                case 2:
                    startTool();
                    break;
                case 3:
                    startRental();
                    break;
                case 4:
                    print("Tak for at bruger denne applikation");
                    exit = true;
                    break;
                default:
                    break;
            }
        }
    }
    
    /**
     * This method distplays the main menu, and then it waits for and registers a choise.
     * 
     * @return  The choise of ther user as an int.
     */
    private int writeMainMenu()
    {
        clr();
        print(" *** Hoved Menu ***");
        print(" (1) Adresse bog");
        print(" (2) Stort værktøj");
        print(" (3) Udlejning");
        print(" (4) Afslut");
        print("\n Foretag din beslutning: ");
            
        boolean exit = false;
        int choise = 0;
        while(!exit)
        {
            try
            {
                Scanner keyboard = new Scanner(System.in);
                choise = keyboard.nextInt();
                exit = true;
            }
            catch(Exception e)
            {
                print("Ugyldigt valg, prøv igen");
            }
        }
        return choise;
    }
    
    /**
     * This method starts the menu for handling the addressbook.
     */
    private void startAddressBook()
    {
        AddressBookUI adrBUI = new AddressBookUI();
        adrBUI.start();
    }
    
    /**
     * This method starts the menu for handling tools.
     */
    private void startTool()
    {
        ToolUI toolUI = new ToolUI();
        toolUI.start();
    }
    
    /**
     * This method starst the menu for handling rentals.
     */
    private void startRental()
    {
        RentalUI rentalUI = new RentalUI();
        rentalUI.start();
    }
    
    /**
     * This methid prints a sting to the terminal
     * 
     * @param   str A sting to be printed to the terminal.
     */
    private void print(String str)
    {
        System.out.println(str);
    }
    
    /**
     * This method clears the terminal.
     */
    private void clr()
    {
        print("\f");
    }
}
